/*
 * Copyright 2010 Joshua Smith and Nelson Llewellyn
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package norse.common;

/**
 * A class that holds a command-line argument and its optional parameter.
 */
public class CommandLineArg
{
    /**
     * Constructor
     *
     * @param _argument The command line argument to pass to a program. Cannot
     *  be empty or null.
     * @param _parameter (Optional) The parameter for this argument.
     */
    public CommandLineArg(String _argument, String _parameter)
    {
        if(_argument == null || _argument.trim().equals(""))
        {
            throw new IllegalArgumentException(
                    "Argument cannot be null or empty");
        }
        argument = _argument;
        parameter = _parameter;

        //Has a paramter if the parameter is non-null and non-empty
        hasParam = (parameter != null && !parameter.trim().equals(""));
    }

    /**
     * Getter.
     *
     * @return the command-line argument.
     */
    public String getArg()
    {
        return argument;
    }

    /**
     * Getter.
     *
     * @return the command-line argument's paramter (if any).
     */
    public String getParam()
    {
        return parameter;
    }

    /**
     * Checks if this command-line argument has a parameter.
     *
     * @return <code>true</code> if there is a paramter; <code>false</code>
     *  otherwise.
     */
    public boolean hasParam()
    {
        return hasParam;
    }

    private final String argument;
    private final String parameter;
    private final boolean hasParam;
}
